<template>
  <el-tag v-if="type == 0" :type="status.type">{{ status.name }}</el-tag>
  <template v-if="type == 1"></template>
</template>

<script setup lang="ts">
const props = defineProps({
  status: { type: String, required: true, default: null },
  /**
   * 显示方式 0 tag 1 text
   */
  type: { type: Number, default: 0 }
})

const status = ref()
watchEffect(() => {
  if (props.status) {
    const statusList: any = props.status.split(',')
    let type = 'info'
    if (statusList[0] > 0) {
      type = 'success'
    } else if (statusList[0] < 0) {
      type = 'danger'
    } else {
      type = 'info'
    }
    status.value = {
      name: statusList[statusList.length - 1],
      value: statusList[0],
      type: type
    }
  }
})
</script>
